package cn.com.infosec.ra.service.log;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.com.infosec.ra.dao.logdao.LogDao;
import cn.com.infosec.ra.entity.AdminOperatorEntity;
import cn.com.infosec.ra.entity.LogEntity;
import cn.com.infosec.ra.util.Pagination;
import cn.com.infosec.ra.util.Util;

@Service
public class LogServiceImpl implements LogService {
	
	@Resource
	private LogDao logDao;
	@Override
	public void saveLog(LogEntity log){
		logDao.saveLog(log);
	}
	@Override
	public void saveLogOracle(LogEntity log) {
		logDao.saveLogOracle(log);
		
	}
	@Override
	public Pagination<LogEntity> queryLogByPagerOracle(
			int operatorOrganid,String account,String targetUser,String startTime,String endTime, Pagination<LogEntity> pager) {
		account = nullToStr(account);
		targetUser = nullToStr(targetUser);
		startTime = (startTime == null || startTime == "")?"":Util.dateToString3(startTime);
		endTime = (endTime == null || endTime == "")?"":Util.dateToString3(endTime);
		List<LogEntity> logList = logDao.queryLogByPagerOracle(
				operatorOrganid,account,targetUser,startTime,endTime, pager);
		List<LogEntity> logListAll = logDao.queryLog(operatorOrganid,account,targetUser,startTime,endTime);
		pager.setItems(logList);
		pager.setCount(logListAll.size());
		return pager;
	}
	@Override
	public Pagination<LogEntity> queryLogByPager(int operatorOrganid,String account,
			String targetUser,String startTime,String endTime,
			Pagination<LogEntity> pager) {
		account = nullToStr(account);
		targetUser = nullToStr(targetUser);
		startTime = (startTime == null || startTime == "")?"":Util.dateToString3(startTime);
		endTime = (endTime == null || endTime == "")?"":Util.dateToString3(endTime);
		List<LogEntity> logList = logDao.queryLogByPager(
				operatorOrganid,account,targetUser,startTime,endTime, pager);
		List<LogEntity> logListAll = logDao.queryLog(operatorOrganid,account,targetUser,startTime,endTime);
		pager.setItems(logList);
		pager.setCount(logListAll.size());
		return pager;
	}
	
	String nullToStr(String str){
		if(str == null)
			return "";
		else
			return str;
	}
}
